#pragma once
#include "D3D9Define.h"
#include "RenderSystem.h"
#include "D3D9RenderWindow.h"
#include "D3D9Device.h"
#include "d3d9.h"
using namespace DreamEngine;

namespace DreamEngineD3D
{

class _EngineD3D9Export CD3D9RenderSystem : public CRenderSystem
{
public:
	CD3D9RenderSystem(void);
	~CD3D9RenderSystem(void);

	virtual Error			Initialize(void);
	virtual Error			ShutDown(void);
	virtual CRenderWindow*	CreateRenderWindow(const CString& name,\
										m_uint16 width, m_uint16 heigth);


	virtual void			BeginFrame(void);
	virtual void			EndFrame(void);

	virtual void			Render(CRenderData* pRenderData);

	static IDirect3D9*		GetD3D9(void)	{return m_pd3d;}
	CD3D9Device*			GetActiveDevice(void)const;

private: 

	virtual void			_SetViewport(CViewport* pViewport);
	
	void					_SetRenderState(CMaterial* pMaterial);
	void					_ActiveVertexBuffer(CRenderData* pRenderData);
	void					_BuildShader(CMaterial* pMaterial);
	void					_BulidDeclaration(const CVertexBuffer::ElementLst& elementLst);
	void					_Draw(CRenderData* pRenderData);

protected:

	static IDirect3D9*				m_pd3d;
};

}
